package P039_UsingAnonymousClassConstructor;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : UsingAnonymousClassConstructor
 * @Description : 使用匿名类的构造函数
 * @Author : wukj1
 * @Date: 2022/3/8 16:29
 **/
public class UsingAnonymousClassConstructor {

    @Test
    public void test(){

        List l1 = new ArrayList();
        List l2 = new ArrayList() {};
        List l3 = new ArrayList() {{

        }{}{}{}};
        System.out.println(l1.getClass() == l2.getClass());
        System.out.println(l2.getClass() == l3.getClass());
        System.out.println(l1.getClass() == l3.getClass());

        List l22 =  new Sub();
        List l33 = new Sub1();

        List l4 = new ArrayList(){{}{}{}};

    }

    //对于l2的理解
    class Sub extends ArrayList{

    }

    //对于l3的理解,因为匿名函数没有构造函数，就用初始化块
    class Sub1 extends ArrayList{
        {

        }
    }

}
